#include <iostream>
#include <string>
#include <math.h>

bool isPrime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

int main() {
    std::string numWords[] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
    std::string input;
    std::cin >> input;

    if (input.length() != 3) {
        std::cout << "Wrong input" << std::endl;
        return 0;
    }

    int number = 0;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 10; j++) {
            if (input.substr(i * 4, 4) == numWords[j]) {
                number = number * 10 + j;
                break;
            }
        }
    }

    if (isPrime(number)) {
        std::cout << number << std::endl;
    } else {
        int lower = number - 1;
        int higher = number + 1;
        while (!isPrime(lower) && !isPrime(higher)) {
            lower--;
            higher++;
        }
        if (isPrime(lower)) {
            std::cout << lower << std::endl;
        } else {
            std::cout << higher << std::endl;
        }
    }

    return 0;
}
